var S = AjaxStack.StringExt;

YAHOO.namespace("ajaxstack");
YAHOO.ajaxstack.StringExt = new YAHOO.tool.TestCase({

	name: "StringExt Tests",

	//--------------------------------------------- 
	// Setup and tear down 
	//---------------------------------------------

	setUp: function()
	{
	},

	tearDown: function()
	{
	},

	//--------------------------------------------- 
	// Tests 
	//---------------------------------------------

	testStartsWith: function()
	{
		Assert.isTrue(S.startsWith("string", "string"));
		Assert.isTrue(S.startsWith("string", "str"));
		Assert.isTrue(S.startsWith("string", "s"));
		Assert.isFalse(S.startsWith("string", "S"));
		Assert.isFalse(S.startsWith("string", "A"));
	},

	testStartsWithAny: function()
	{
		Assert.isTrue(S.startsWithAny("string", ["string"]));
		Assert.isTrue(S.startsWithAny("string", ["a", "string", "b"]));
		Assert.isTrue(S.startsWithAny("string", ["a", "str", "b"]));
		Assert.isTrue(S.startsWithAny("string", ["a", "b", "str"]));
		Assert.isFalse(S.startsWithAny("string", ["Str"]));
		Assert.isFalse(S.startsWithAny("string", ["S"]));
	},

	testEscapeHtml: function()
	{
		Assert.areEqual("&lt;b&gt;1 &amp; 2 test&lt;/b&gt;", S.escapeHtml("<b>1 & 2 test</b>"));
	},

	testCropText: function()
	{
		Assert.areEqual("This ..", S.cropText("This is english text", 5));
	},

	testChop: function()
	{
		Assert.areEqual("This is english", S.chop("This is english text", 5));
	},

	testEquals: function()
	{
		Assert.isTrue(S.equals("This", "This"));
		Assert.isFalse(S.equals("This", "this"));
		Assert.isFalse(S.equals("This", ["this"]));
		Assert.isFalse(S.equals("This", { "this": "this" }));
		Assert.isTrue(S.equals("1", 1));
		Assert.isTrue(S.equals("This", { toString: function() { return "This"; } }));
	},

	testPadLeft: function()
	{
		Assert.areEqual("001", S.padLeft("1", 3));
		Assert.areEqual("001", S.padLeft(1, 3));
		Assert.areEqual("  1", S.padLeft(1, 3, " "));
	},

	testLPad: function()
	{
		Assert.areEqual("001", S.lpad("1", 3));
		Assert.areEqual("001", S.lpad(1, 3));
		Assert.areEqual("  1", S.lpad(1, 3, " "));
	},

	testPadRight: function()
	{
		Assert.areEqual("100", S.padRight("1", 3));
		Assert.areEqual("100", S.padRight(1, 3));
		Assert.areEqual("1  ", S.padRight(1, 3, " "));
	},

	testRPad: function()
	{
		Assert.areEqual("100", S.rpad("1", 3));
		Assert.areEqual("100", S.rpad(1, 3));
		Assert.areEqual("1  ", S.rpad(1, 3, " "));
	},

	testCreateAttr: function()
	{
		Assert.areEqual('a="b"', S.createAttr({ a: 'b' }));
		Assert.areEqual('a="b" c="d" e="f"', S.createAttr({ a: 'b', c: 'd', e: 'f' }));
	},

	testEat: function()
	{
		Assert.areEqual(" is english text", S.eat("This is english text", "This"));
		Assert.areEqual(" is english text", S.eat("This is english text", "is"));
		Assert.areEqual("h text", S.eat("This is english text", "is", true));
	},

	testCat: function()
	{
		Assert.areEqual("/path/to/file", S.cat('/',"path",'/','to','/','file'));
	},

	testToString: function()
	{
		Assert.areEqual("1", S.toString(1));
		Assert.areEqual("[a]", S.toString(['a']));
		Assert.areEqual("[1]", S.toString([1]));
		Assert.areEqual("[a,1,b]", S.toString(['a', 1, 'b']));
		Assert.areEqual("{a=b}", S.toString({ a: 'b' }));
	},

	testTrim: function()
	{
		Assert.areEqual("a", S.trim(" a "));
		Assert.areEqual("a", S.trim("  a"));
		Assert.areEqual("a", S.trim("a  "));
	},

	testLTrim: function()
	{
		Assert.areEqual("a ", S.ltrim(" a "));
		Assert.areEqual("a", S.ltrim("  a"));
		Assert.areEqual("a  ", S.ltrim("a  "));
	},

	testRTrim: function()
	{
		Assert.areEqual(" a", S.rtrim(" a "));
		Assert.areEqual("  a", S.rtrim("  a"));
		Assert.areEqual("a", S.rtrim("a  "));
	},

});

